package officers;

import com.sun.jmx.remote.internal.ArrayQueue;

import java.util.*;

public class Problem32_1 {
    public int[] levelOrder(TreeNode root) {
//        Deque<TreeNode> que=new Deque<TreeNode>();
        if (root == null) return null;

        Deque<TreeNode> que = new LinkedList();
        que.push(root);
        ArrayList<Integer> res=new ArrayList<>();
        while(!que.isEmpty()){
            TreeNode cur=que.poll();
            res.add(cur.val);
            if(cur.left!=null) que.add(cur.left);
            if(cur.right!=null) que.add(cur.right);
        }
        int []x=new int[res.size()];
        for(int i=0;i<res.size();i++){
            x[i]=res.get(i);
        }
        return x;
    }
}
